# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=lz4
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.9.4
pkgrel=1
pkgdesc="Very fast lossless compression algorithm (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32' 'clangarm64')
url="https://lz4.github.io/lz4/"
license=('BSD' 'GPL2')
makedepends=("${MINGW_PACKAGE_PREFIX}-cc")
checkdepends=('diffutils')
options=('staticlibs' 'strip')
source=(${_realname}-${pkgver}.tar.gz::"https://github.com/lz4/lz4/archive/v${pkgver}.tar.gz")
sha256sums=('0b0e3aa07c8c063ddf40b082bdf7e37a1562bda40a0ff5272957f3e987e0e54b')

build() {
  [[ -d "${srcdir}/build-${MSYSTEM}" ]] && rm -rf "${srcdir}/build-${MSYSTEM}"
  cp -rf "${srcdir}/${_realname}-${pkgver}" "${srcdir}/build-${MSYSTEM}"
  cd "${srcdir}/build-${MSYSTEM}"

  make CC=${MINGW_PREFIX}/bin/cc
}

check() {
  cd ${srcdir}
  msg2 "rm -f profile.lz4"
  rm -f profile.lz4 || true

  ${srcdir}/build-${MSYSTEM}/programs/lz4 /etc/profile profile.lz4
  ${srcdir}/build-${MSYSTEM}/programs/lz4 -d profile.lz4 profile
  diff -q /etc/profile profile

  rm profile

#  cd "${srcdir}/build-${MSYSTEM}"
#  make test
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"
  make CC=${MINGW_PREFIX}/bin/cc DESTDIR="${pkgdir}" PREFIX=${MINGW_PREFIX} install
}
